package se.webbzon.boltzmann.effect;

import se.webbzon.boltzmann.game.object.camera.GameCamera;
import se.webbzon.oschi01.worldarea.WorldArea;

public class GameCameraShakeEffect extends GameCameraEffect {
	
	private final double magnitude;
	
	/*============================================================
	Constructors
	============================================================*/

	public GameCameraShakeEffect(GameCamera camera, int duration, double magnitude) {
		super(camera, duration);
		this.magnitude = magnitude;
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	@Override public void onEffectBegin(WorldArea world) {
		
	}

	@Override public void onEffectStep(WorldArea world) {
		final double t = 1 - getDuration() / (double) getStartupDuration();
		getCamera().setOffset(0, magnitude * Math.exp(-t*3) * Math.sin(8*Math.PI*t), 0);
	}

	@Override public void onEffectEnd(WorldArea world) {
		getCamera().setOffset(0, 0, 0);
	}

}
